package hottargui.config;

import hottargui.framework.Game;
import hottargui.framework.GameListener;
import hottargui.framework.GameObjectServer;
import hottargui.framework.Player;
import hottargui.framework.PlayerColor;
import hottargui.framework.Position;
import hottargui.framework.State;
import hottargui.framework.TarguiFactory;
import hottargui.framework.TarguiState;
import hottargui.framework.Tile;

import java.util.Iterator;
import java.util.List;

/**
 * AlphaGame implementation. Presently simply a temporary test stub to be
 * expanded by a test-driven process.
 */

public class AlphaGame implements Game {

	TarguiState currentState;
	TarguiFactory factory;
	GameObjectServer objectServer;

	public AlphaGame(AlphaTarguiFactory alphafactory) {
		factory = alphafactory;
		objectServer = factory.getGameObjectServer();

		// initialize state
		currentState = factory.getNewGameState(this);
	}

	public TarguiFactory getFactory() {
		return factory;
	}

	public void newGame() {
		currentState.newGame();
	}

	/** return a specific tile */
	// TODO This might have possibilities for optimizations...
	public Tile getTile(Position p) {
		List<Tile> boardConf = objectServer.getGameData()
				.getBoardConfiguration();
		for (Tile tile : boardConf) {
			if (tile.getPosition().equals(p)) {
				return tile;
			}
		}
		return null;
	}

	public Player getPlayerInTurn() {
		return objectServer.getGameData().getCurrentPlayer();
	}

	public State getState() {
		return currentState.getState();
	}

	public boolean move(Position from, Position to, int count) {
		return currentState.move(from, to, count);
	}

	public boolean buy(int count, Position deploy) {
		return currentState.buy(count, deploy);
	}

	public PlayerColor turnCard() {
		return currentState.turnCard();
	}

	public void rollDie() {
	}

	public int getDieValue() {
		return 1;
	}

	public void setState(TarguiState newState) {
		this.currentState = newState;
	}

	public Iterator<Tile> getBoardIterator() {
		return null;
	}

	public void addGameListener(GameListener observer) {
	}

	public void report(String s) {
	}

	public GameObjectServer getGameObjectServer() {
		return objectServer;
	}

	public PlayerColor getWinner() {
		return currentState.getWinner();
	}
}
